const mongoose = require('mongoose')
const mongoosePaginate = require('mongoose-paginate')
const path = require('path')

module.exports = function (db) {
    return db.model(path.basename(__filename, path.extname(__filename)), new mongoose.Schema(
        {
            app_name: {
                type: String,
                index: true,
            },

            app_key: {      // 以单位为基本配置
                type: String,
                index: true,
            },

            im_suffix: {   // im 番号后缀
                type: String,
                index: true,
                default: '',
            },

            // 分布式自动自动选主
            client_ids: {
                type: [String],
                default:[],
                index: true,
            },

            list: [{
                unit_id: {
                    type: String,
                    index: true,
                },
                device_id: {
                    type: String,
                    index: true,
                },
                event_id: {
                    type: String,
                    index: true,
                },
                region_code: {
                    type: String,
                    index: true
                }
            }]
        },
        {
            collection: path.basename(__filename, path.extname(__filename)),
            timestamps: { createdAt: 'created_at', updatedAt: 'updated_at' }
        }).plugin(mongoosePaginate)
    )
}
